#!/usr/bin/ruby
require 'fox16'

require './Bd'
require './treeview'
require './tableBD'
include Fox
# coding: utf-8

class Mainwindow < FXMainWindow
  include Usuarios
  def initialize(app)
    super(app, "STG", :width => 1024, :height => 768)
    
    packer = FXPacker.new(self, :opts => LAYOUT_FILL)
    # Barra de estado
    FXStatusBar.new(self, LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|STATUSBAR_WITH_DRAGCORNER)
    
    @mdiclient = FXMDIClient.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y)
    splitter = FXSplitter.new(packer, (LAYOUT_SIDE_TOP|LAYOUT_FILL_X|
                LAYOUT_FILL_Y|SPLITTER_REVERSED|SPLITTER_TRACKING))
    treelist_frame = FXVerticalFrame.new(splitter, FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_Y, :width =>100, :height => 200)
    mainframe= FXVerticalFrame.new(splitter, FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y)
    busqueda = FXVerticalFrame.new(mainframe,         LAYOUT_FILL_X)
    principal = FXHorizontalFrame.new(mainframe, FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y)
    tabla =  TableBD.new(principal,"MOD_propiedades");
    
    #k=Bd.new('')
    #imgprincipal=Bd.makeImg(getApp(),'erp.jpg')
    #FXImageView.new(principal, imgprincipal, :opts => FRAME_RAISED|FRAME_THICK|LAYOUT_FILL|IMAGEVIEW_CENTER_Y)
    btn = FXButton.new(busqueda, "Sin validar", nil, nil, 0, JUSTIFY_LEFT|FRAME_RAISED|FRAME_THICK|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT, 0,0,800,20,0,0,0,0) #0, 0, 800, 20)
    btn.backColor=Fox.FXRGB(255, 255, 255)
    btn.textColor=Fox.FXRGB(255, 0, 0)
    #btn.text=
    btn.connect(SEL_COMMAND){
      btn.text="Seleccion de Usuario"
    }
    #btn.backGround = FXColor::White
    
=begin   
   Usuarios.elegirusuario(principal)
    
   FXStatusBar.new(self, LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|STATUSBAR_WITH_DRAGCORNER)
  
    @mdimenu = FXMDIMenu.new(self, @mdiclient)
=end    
  
    # MDI buttons in menu:- note the message ID's!!!!!
    # Normally, MDI commands are simply sensitized or desensitized;
    # Under the menubar, however, they're hidden if the MDI Client is
    # not maximized.  To do this, they must have different ID's.
=begin
    FXMDIWindowButton.new(menubar, @mdimenu, @mdiclient, FXMDIClient::ID_MDI_MENUWINDOW,
      LAYOUT_LEFT)
    FXMDIDeleteButton.new(menubar, @mdiclient, FXMDIClient::ID_MDI_MENUCLOSE,
      FRAME_RAISED|LAYOUT_RIGHT)
    FXMDIRestoreButton.new(menubar, @mdiclient, FXMDIClient::ID_MDI_MENURESTORE,
      FRAME_RAISED|LAYOUT_RIGHT)
    FXMDIMinimizeButton.new(menubar, @mdiclient,
      FXMDIClient::ID_MDI_MENUMINIMIZE, FRAME_RAISED|LAYOUT_RIGHT)
=end
=begin  
    # menu.run('menupaths')
    #menu.create(app,treelist_frame)
    
    FXLabel.new(principal, "Usuario: ")

    @name_target = FXDataTarget.new("")
    name_text = FXTextField.new(principal, 25,
      :target => @name_target, :selector => FXDataTarget::ID_VALUE)
    @name_target.connect(SEL_COMMAND) do
      puts "The name is #{@name_target.value}"
    end

    FXLabel.new(principal, "User ID: ")
    userid_text = FXTextField.new(principal, 25)

    userid_text.connect(SEL_VERIFY) do |sender, sel, tentative|
      if tentative =~ /^[a-zA-Z][a-zA-Z0-9]*$/
        false
      else
        true
      end
    end	
=end

    menu=FXFoldingListBd.new(treelist_frame,'menupaths')
    


=begin
    selected_items = []
    treelist.connect(SEL_SELECTED) do |sender, sel, item|
      selected_items << item unless selected_items.include? item
    end
    treelist.connect(SEL_DESELECTED) do |sender, sel, item|
      selected_items.delete(item)
    end



    treelist.connect(SEL_COMMAND) do |sender, sel, current|
      selected_items = []
      treelist.each { |child| add_selected_items(child, selected_items) }
    end


    treelist.connect(SEL_RIGHTBUTTONRELEASE) do |sender, sel, event|
      unless event.moved?
        item = sender.getItemAt(event.win_x, event.win_y)
        unless item.nil?


          # ...



          FXMenuPane.new(self) do |menu_pane|
            play = FXMenuCommand.new(menu_pane, "Play Song")
            play.connect(SEL_COMMAND) { play_song_for(item) }
            info = FXMenuCommand.new(menu_pane, "Get Info")
            info.connect(SEL_COMMAND) { display_info_for(item) }

            # ...


            menu_pane.create
            menu_pane.popup(nil, event.root_x, event.root_y)
            app.runModalWhileShown(menu_pane)
            

          end
        end
      end
      
    end
=end


  end
  
  def play_song_for(item); end
  
  def display_info_for(item); end
  

  def add_selected_items(item, selected_items)
    selected_items << item if item.selected?
    item.each { |child| add_selected_items(child, selected_items) }
  end


  def create
    super
    show(PLACEMENT_SCREEN)
  end
end

if __FILE__ == $0
  FXApp.new do |app|
    Mainwindow.new(app)
    app.create
    app.run
  end
end